<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>邮箱注册</title>

</head>
<body>
<div>
    <form action="/user/register" method="post" onsubmit="return sub()">
        <table>
            <tr>
                <th colspan="2">注册</th>
            </tr>
            <tr>
                <td>账号</td><td><input type="text" id="idNumber" name="idNumber" placeholder="请输入手机号或邮箱" /></td>
            </tr>
            <tr>
                <td>用户名</td><td><input type="text" id="userName" name="userName" /></td>
            </tr>
            <tr>
                <td>密码</td><td><input type="password" id="password" name="password" /></td>
            </tr>
            <tr>
                <td>确认密码</td><td><input type="password" id="repassword"  /></td>
            </tr>
            <tr>
                <td colspan="2"><span th:text="${msg}"></span></td>
            </tr>
            <tr>
                <td><input type="submit" value="注册"  /></td>
                <td><input type="reset" value="重置"  /></td>
            </tr>
        </table>
    </form>
</div>
<script src="/js/jquery.min.js"></script>
<script>

    function sub() {
        var userName = $("#userName").val().trim();
        var password = $("#password").val().trim();
        var repassword = $("#repassword").val().trim();
        var idNumber = $("#idNumber").val().trim();
        if (idNumber == "") {
            alert("请输入账号");
            return false
        }
        if (userName == "") {
            alert("请输入用户名");
            return false
        }
        if (password == "") {
            alert("请输入密码");
            return false
        }
        if (repassword == "") {
            alert("请输入确认密码");
            return false
        }
        if (repassword != password) {
            alert("两次输入的密码不一致");
            return false;
        }
        return true;

    }
    /*
        $(function() {

            $("#register").click(function() {
                var userName = $("#userName").val();
                var password = $("#password").val();
                var idNumber = $("#idNumber").val();
                var data = {userName, password};
                if (idNumber.includes("@")) {
                    data.email = idNumber;
                } else {
                    data.cellphone = idNumber;
                }
                $.ajax({
                    url: 'http://localhost:8080/user/register',
                    method: 'POST',
                    dataType: 'text',
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(data),
                    success: function(response) {
                        alert("注册成功");
                        location.href = "http://localhost:8080/page/toLogin";
                    }
                });
            });

        });
        */


    </script>
</body>
</html>